package com.qpkj.oms.service.impl;

import java.util.List;

import com.qpkj.oms.domain.OmsTask;
import com.qpkj.oms.mapper.OmsTaskMapper;
import com.qpkj.system.mapper.SysUserMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qpkj.oms.mapper.OmsTaskRemarkMapper;
import com.qpkj.oms.domain.OmsTaskRemark;
import com.qpkj.oms.service.IOmsTaskRemarkService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 任务备注Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-24
 */
@Service
public class OmsTaskRemarkServiceImpl implements IOmsTaskRemarkService {
    @Autowired
    private OmsTaskRemarkMapper omsTaskRemarkMapper;
    @Autowired
    private OmsTaskMapper taskMapper;
    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询任务备注
     *
     * @param remarkId 任务备注主键
     * @return 任务备注
     */
    @Override
    public OmsTaskRemark selectOmsTaskRemarkByRemarkId(Long remarkId) {
        return omsTaskRemarkMapper.selectOmsTaskRemarkByRemarkId(remarkId);
    }

    /**
     * 查询任务备注列表
     *
     * @param omsTaskRemark 任务备注
     * @return 任务备注
     */
    @Override
    public List<OmsTaskRemark> selectOmsTaskRemarkList(OmsTaskRemark omsTaskRemark) {
        List<OmsTaskRemark> remarkList=omsTaskRemarkMapper.selectOmsTaskRemarkList(omsTaskRemark);
        remarkList.forEach(omsTaskRemark1 -> {
            if (ObjectUtils.isEmpty(omsTaskRemark1.getUserId())){
                omsTaskRemark1.setCreateBy(userMapper.selectUserById(omsTaskRemark1.getUserId()).getUserName());
            }
        });
        return remarkList;
    }

    /**
     * 新增任务备注
     *
     * @param omsTaskRemark 任务备注
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertOmsTaskRemark(OmsTaskRemark omsTaskRemark) {
        OmsTask task = taskMapper.selectOmsTaskByTaskId(omsTaskRemark.getTaskId());
        if (!ObjectUtils.isEmpty(task)) {
            task.setHaveRemark("1");
            taskMapper.updateOmsTask(task);
        }
        return omsTaskRemarkMapper.insertOmsTaskRemark(omsTaskRemark);
    }

    /**
     * 修改任务备注
     *
     * @param omsTaskRemark 任务备注
     * @return 结果
     */
    @Override
    public int updateOmsTaskRemark(OmsTaskRemark omsTaskRemark) {
        return omsTaskRemarkMapper.updateOmsTaskRemark(omsTaskRemark);
    }

    /**
     * 批量删除任务备注
     *
     * @param remarkIds 需要删除的任务备注主键
     * @return 结果
     */
    @Override
    public int deleteOmsTaskRemarkByRemarkIds(Long[] remarkIds) {
        return omsTaskRemarkMapper.deleteOmsTaskRemarkByRemarkIds(remarkIds);
    }

    /**
     * 删除任务备注信息
     *
     * @param remarkId 任务备注主键
     * @return 结果
     */
    @Override
    public int deleteOmsTaskRemarkByRemarkId(Long remarkId) {
        return omsTaskRemarkMapper.deleteOmsTaskRemarkByRemarkId(remarkId);
    }
}
